﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;

namespace ProjectNocturnalFool
{
    /// <summary>
    /// Enum used for various KEYs.
    /// </summary>
    public enum ENUM_KEY    
    {
        KEY_START,
        KEY_REJECT,
        KEY_1,
        KEY_2,
        KEY_3,
        KEY_4,
        KEY_UP,
        KEY_DOWN,
        KEY_LEFT,
        KEY_RIGHT
    }

    /// <summary>
    /// Keeps track of inputs for a player profile
    /// </summary>
    public class PlayerKeyConfig
    {

        public Keys key1 { get; set; }
        public Keys key2 { get; set; }
        public Keys key3 { get; set; }
        public Keys key4 { get; set; }

        public Keys keyUp { get; set; }
        public Keys keyDown { get; set; }
        public Keys keyLeft { get; set; }
        public Keys keyRight { get; set; }

        public Keys keyAccept { get; set; }
        public Keys keyReject { get; set; }

        public Dictionary<ENUM_KEY, Keys> enumToKeyMap;

        public PlayerKeyConfig(int playerNumber)
        {
            enumToKeyMap =new Dictionary<ENUM_KEY,Keys>();

            keyAccept = Keys.Enter;
            keyReject = Keys.Escape;
            key1 = Keys.D1;
            key2 = Keys.D2;
            key3 = Keys.D3;
            key4 = Keys.D4;

            keyUp = Keys.Up;
            keyDown = Keys.Down;
            keyLeft = Keys.Right;
            keyRight = Keys.Left;

            remapDictionary();

            Keys outputKey = Keys.None;
            enumToKeyMap.TryGetValue(ENUM_KEY.KEY_1, out outputKey);

            key1 = Keys.D2;

            outputKey = Keys.None;
            enumToKeyMap.TryGetValue(ENUM_KEY.KEY_1, out outputKey);

            key1 = Keys.D3;

        }

        public Keys getKey(ENUM_KEY input)
        {
            Keys outputKey = Keys.None;
            enumToKeyMap.TryGetValue(input, out outputKey);
            return outputKey;
        }

        private void remapDictionary()
        {
            enumToKeyMap.Add(ENUM_KEY.KEY_1, key1);
            enumToKeyMap.Add(ENUM_KEY.KEY_2, key2);
            enumToKeyMap.Add(ENUM_KEY.KEY_3, key3);
            enumToKeyMap.Add(ENUM_KEY.KEY_4, key4);

            enumToKeyMap.Add(ENUM_KEY.KEY_UP, keyUp);
            enumToKeyMap.Add(ENUM_KEY.KEY_DOWN, keyDown);
            enumToKeyMap.Add(ENUM_KEY.KEY_LEFT, keyLeft);
            enumToKeyMap.Add(ENUM_KEY.KEY_RIGHT, keyRight);

            enumToKeyMap.Add(ENUM_KEY.KEY_START, keyAccept);
            enumToKeyMap.Add(ENUM_KEY.KEY_REJECT, keyReject);
        }


    }
}
